package com.demo.FileInputStream_;

import org.apache.log4j.Logger;
import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @author gy
 * @date 2022/4/4
 */

public class FileInputStream01 {

    private static final Logger logger = Logger.getLogger(FileInputStream01.class);

    @Test
    public void m1() {
        String filePath = "f:\\20220403\\new2.txt";

        FileInputStream fileInputStream = null;
        byte[] aByte = new byte[8];
        int read = 0;
        try {
            logger.info("创建文件输入流对象");
            fileInputStream = new FileInputStream(filePath);

            while ((read = fileInputStream.read(aByte)) != -1) {
                System.out.print(new String(aByte, 0, read));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (fileInputStream != null) {
                    fileInputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
